package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 频道信息控制器
 *
 * @Name : WmChannelController
 * @Author : WuQiang
 * @Date : 2022-09-28 11:14
 * @Description : 频道信息控制器
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 分页查询  + 模糊查询
     *
     * @param dto dto
     * @return {@code ResponseResult}
     */
    @PostMapping("list")
    @ApiOperation(value = "根据名称模糊查询分页列表", notes = "author:wq")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true, dataType = "ChannelDto")
    public ResponseResult getListByPage(@RequestBody ChannelDto dto) {
        return wmChannelService.page(dto);
    }

    /**
     * 频道新增
     *
     * @param wmChannel 频道实体
     * @return {@code ResponseResult}
     */
    @PostMapping
    @ApiOperation(value = "频道新增")
    @ApiImplicitParam(name = "wmChannel", value = "新增对象", required = true, dataType = "WmChannel")
    public ResponseResult saveWmChannel(@RequestBody WmChannel wmChannel) {
        return wmChannelService.saveWmChannel(wmChannel);
    }

    /**
     * 频道修改
     *
     * @param wmChannel 频道管理实体
     * @return {@code ResponseResult}
     */
    @PutMapping
    @ApiOperation(value = "频道修改", notes = "同时适配修改状态、启用与禁用")
    @ApiImplicitParam(name = "wmChannel", value = "修改对象", required = true)
    public ResponseResult updateWmChannel(@RequestBody WmChannel wmChannel) {
        return wmChannelService.updateWmChannel(wmChannel);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除频道", notes = "逻辑删除")
    @ApiImplicitParam(name = "id", value = "Integer", required = true, dataType = "Integer")
    public ResponseResult deleteWmChannelById(@PathVariable Integer id) {
        return wmChannelService.deleteById(id);
    }


    /**
     * 获取频道列表
     */
    @GetMapping("channels")
    public ResponseResult<List<WmChannel>> getChannels() {
        List<WmChannel> channelList = wmChannelService.list();
        return ResponseResult.okResult(channelList);
    }

}
